<?php
/*
 * Author :pandiam
 */
session_start();
require_once('../BL/BL.php');


$old_pass = $_POST['old_password'];
$new_pass = $_POST['new_password'];
$new_pass_check = $_POST['new_password_check'];
$email = $_POST['email'];
$email_check = $_POST['email_check'];
$username = $_POST['username'];
$name = $_POST['name'];
$surname = $_POST['surname'];


$userid = $_SESSION['uid'];

$user = BL_GetUserData($userid);



if($name != ""){
	$user->SetName($name);
}
if($surname != ""){
	$user->SetSurname($surname);
}
if($new_pass != ""){
	if($user->GetPassword == $old_pass){
		if($new_pass == $new_pass_check){
			$user->SetPassword($new_pass);
		}
	}
}

if($email != ""){
	if($email == $email_check){
		if(!DB_emailExists($email) ){
			$user->setEmail($email);
		}

	}
}

if(BL_SetUser($user) < 0){
	UI_registerError('msg_error', "Error changing your data");
}
else {
	UI_registerError('msg_success', "Data Changed Successfully");

}

header('location:profile.php');

?>
